package com.ztesoft.web.taskgenerator.taskjob;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import com.ztesoft.framework.log.ZTEsoftLogManager;
import com.ztesoft.framework.util.DateUtils;
import com.ztesoft.web.common.Configuration;

/**
 * @description 定时器定义，加载任务
 * @version
 * @date 2015年06月04日
 */
public class LoadTask {
	private static final ZTEsoftLogManager logger = ZTEsoftLogManager
            .getLogger(TaskJob.class);
	
	 public void initTask() throws SchedulerException{
		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler scheduler;
		scheduler = sf.getScheduler();
		//加载任务
		JobDetail job = JobBuilder.newJob(TaskJob.class)
				.withIdentity("job1", "group1").build();
		CronTrigger trigger = TriggerBuilder.newTrigger()
			    .withIdentity("trigger1", "group1")
			    .withSchedule(CronScheduleBuilder.cronSchedule(Configuration.getString("quartzTime")))
			    .forJob(job)
			    .build();
			scheduler.scheduleJob(job, trigger);
			try {
			if(Configuration.getBoolean("dmTaskJobStart",true)){
				logger.info("||Taskgenerator Start||"+DateUtils.getCurrentDate());
				scheduler.start();
				logger.debug("||Taskgenerator End||"+DateUtils.getCurrentDate());
			}
			} catch (SchedulerException e) {
				logger.error("||Taskgenerator Error||"+e);
			}
	}

}
	
